package com.huaxin.hxcloud.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import com.huaxin.common.BaseActivity;
import com.huaxin.common.Constants;
import com.huaxin.hxcloud.R;
import com.huaxin.hxcloud.fragment.HxNoticeListFragment;
import com.huaxin.hxcloud.fragment.WarningListFragment;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/9/21.
 * 工作模块 告警
 */
public class WarningListActivity extends BaseActivity {


    @BindView(R.id.tab)
    TabLayout tab;
    @BindView(R.id.pager)
    ViewPager pager;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.appbar)
    AppBarLayout appbar;
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private MyAdapter adapter = new MyAdapter(getSupportFragmentManager());

    private HxNoticeListFragment mNoticeFragment;
    private WarningListFragment mWarningFragment;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_warning_list;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        toolbar.setTitle("提示消息");
        setSupportActionBar(toolbar);
        mWarningFragment = new WarningListFragment();
        Bundle warningBundle = new Bundle();
        warningBundle.putInt("type", Constants.WARNING_TYPE_WARING);
        mWarningFragment.setArguments(warningBundle);

        Bundle noticeBundle = new Bundle();
        noticeBundle.putInt("type", Constants.WARNING_TYPE_NOTICE);
        mNoticeFragment = new HxNoticeListFragment();
        mNoticeFragment.setArguments(noticeBundle);
        fragments.add(mWarningFragment);
        fragments.add(mNoticeFragment);
        pager.setAdapter(adapter);
        tab.setupWithViewPager(pager);
        tab.getTabAt(0).setText("告警");
        tab.getTabAt(1).setText("公告");
        int index = getIntent().getIntExtra("index", 0);
        pager.setCurrentItem(index);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
    protected class MyAdapter extends FragmentPagerAdapter {

        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }
    }

}
